<template>
	<view class="container">
		<!-- 立即评价 -->
		<u-navbar leftIcon="arrow-left" @leftClick="back" title="汽车保养" bg-color="#00000000" titleStyle="color:#fff"
			leftIconColor="#fff" placeholder></u-navbar>

		<view class="content">
			<!-- 背景 -->
			<view class="top-bg"></view>

			<view class="main">
				<view class="tab-content">
					<view class="list">
						<view class="top">
							<text class="title">服务评价</text>
						</view>
						<view class="line"></view>
						<view class="info">
							<image src="../../../static/images/evaluate-shop.png" mode=""></image>
							<view class="text">
								<text>车百事汽车生活馆</text>
								<u-rate :count="count" v-model="value" active-color="#FFC100"
									style="margin-top: 20rpx;"></u-rate>
							</view>
						</view>
					</view>
					<view class="list">
						<view class="top">
							<text class="title">评语 </text>
							<text class="name">(0-299字)</text>
						</view>
						<textarea name="" id="" cols="40" rows="8" placeholder="请留下您宝贵的意见和建议....."></textarea>
					</view>

					<view class="list">
						<view class="top">
							<text class="title">照片 </text>
							<text class="name">(选填)</text>
						</view>
						<u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple
							:maxCount="3" :previewFullImage="true" :deletable="true" width="160rpx" height="160rpx" style="margin-top: 20rpx;">
							<view class="upload">
								<image src="../../../static/images/plus-car.png" mode=""></image>
								<text>上传照片</text>
							</view>
						</u-upload>
					</view>
					
					<button class="submit">提交</button>
				</view>
			</view>
		</view>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				count: 5,
				value: 5,
				fileList1: [],
			};
		},
		onLoad(option) {},
		methods: {
			// 返回
			back() {
				uni.navigateBack({});
			},


			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: './upload', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							setTimeout(() => {
								resolve(res.data.data)
							}, 1000)
						}
					});
				})
			},
		}
	}
</script>

<style lang="scss">
	.content {
		position: absolute;
		top: 0;

		uni-button:after {
			border: transparent;
		}

		.top-bg {
			width: 750rpx;
			height: 400rpx;
			// background-image: url('http://www.img.ttblog.cn/car/header-bg.png');
			background-color: #3384FC;
			background-size: cover;
		}

		.main {
			transform: translateY(-170rpx);
			margin-top: -70rpx;
			padding: 0 20rpx;

			.list {
				padding: 30rpx 30rpx;
				background-color: #fff;
				border-radius: 20rpx;
				margin-bottom: 30rpx;

				.top {
					.title {
						font-size: 32rpx;
					}
				}

				.line {
					border-bottom: 7rpx solid #f7f7f7;
					padding-top: 18rpx;
				}

				.info {
					display: flex;
					flex-direction: row;
					align-items: center;
					margin-top: 20rpx;

					image {
						width: 180rpx;
						height: 120rpx;
					}

					.text {
						display: flex;
						flex-direction: column;
						align-items: center;
						font-size: 24rpx;
						margin-left: 20rpx;
					}
				}

				textarea {
					margin-top: 20rpx;
					border: 1rpx solid #ccc;
					border-radius: 20rpx;
					font-size: 24rpx;
					width: 100%;
					height: 240rpx;
					padding: 20rpx;
					box-sizing: border-box;
				}

				.name {
					font-size: 24rpx;
					margin-top: 18rpx;
					display: inline-block;
				}
				
				// 上传样式
				.upload{
					border: 1rpx solid #ccc;
					border-radius: 20rpx;
					width: 160rpx;
					height: 160rpx;
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: center;
					
					image{
						width: 40rpx;
						height: 40rpx;
						margin-bottom: 20rpx;
					}
					
					text{
						font-size: 24rpx;
						color: #ccc;
					}
				}
			}
			
			.submit{
				color: #fff;
				font-size: 30rpx;
				background-color: #3384FC;
				width: 75%;
				border-radius: 60rpx;
				margin-top: 50rpx;
			}

			.placeholder {
				height: 15.33vw;
			}

			/deep/ .u-button {
				width: 80%;
				background-color: #D9D9D9;
				color: #fff;
			}
		}
	}
</style>